package com.app.sgd.business.dao;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.apache.struts.util.LabelValueBean;

import com.app.sgd.plugin.JNDIConnector;
import com.app.sgd.util.Constants;

public class OracleVariablesSessionDAO {
private static Logger logger = Logger.getLogger(SQLDocumentoDAO.class);
	
	DataSource ds = null;
	JNDIConnector cn = new JNDIConnector();
	
	public ArrayList getTipoProcesoExpBCA() throws Exception {
		ArrayList lstObjeto = new ArrayList();
		Connection conn = null;
		PreparedStatement pre = null;
		CallableStatement call = null;
		ResultSet rs = null;
		try{
			conn = cn.connect(0).getConnection();
	    	
			String vSQL = " SELECT CODIGOTIPOEXPEDIENTEBCA" +
					 	  "       ,DESCRIPCIONTIPOEXPEDIENTEBCA " +
					 	  "   FROM TIPOEXPEDIENTEBCA " +
					 	  "  ORDER BY DESCRIPCIONTIPOEXPEDIENTEBCA";
	    	
			pre = conn.prepareStatement(vSQL);
			logger.info("ini: " + new Date());
            rs = pre.executeQuery();
            logger.info("fin: " + new Date());
            int ind=0;
            lstObjeto.add(new LabelValueBean(Constants.VALOR_DEFAULT_TODOS,Constants.VALOR_DEFAULT_CERO));
            while(rs.next()){
            	lstObjeto.add(new LabelValueBean(rs.getString("DESCRIPCIONTIPOEXPEDIENTEBCA"),rs.getString("CODIGOTIPOEXPEDIENTEBCA")));
            }
		}catch(Exception e){
			logger.error("[STD]: Error en getTipoProcesoExpBCA: " + e.getMessage());
            e.printStackTrace();
		}
		finally{
			cn.destroy(conn,null,rs,call,pre);
		}
		return lstObjeto;
	}
	
	public ArrayList getTipoEstadoExpBCA() throws Exception {
		ArrayList lstObjeto = new ArrayList();
		Connection conn = null;
		PreparedStatement pre = null;
		CallableStatement call = null;
		ResultSet rs = null;
		try{
			conn = cn.connect(0).getConnection();
	    	
			String vSQL = " SELECT CODIGOESTADOITEMBCA" +
						  "       ,DESCRIPCIONESTADOITEMBCA " +
						  "   FROM ESTADOITEMEXPDIENTEBCA " +
						  "  WHERE CODIGOESTADOITEMBCA <> 'DE'" +
						  "  ORDER BY DESCRIPCIONESTADOITEMBCA";

			pre = conn.prepareStatement(vSQL);
			logger.info("ini: " + new Date());
			rs = pre.executeQuery();
			logger.info("fin: " + new Date());
			int ind=0;
			lstObjeto.add(new LabelValueBean(Constants.VALOR_DEFAULT_TODOS,Constants.VALOR_DEFAULT_CERO));
			while(rs.next()){
				lstObjeto.add(new LabelValueBean(rs.getString("DESCRIPCIONESTADOITEMBCA"),rs.getString("CODIGOESTADOITEMBCA")));
			}
		}catch(Exception e){
			logger.error("[STD]: Error en getTipoProcesoExpBCA: " + e.getMessage());
            e.printStackTrace();
		}
		finally{
			cn.destroy(conn,null,rs,call,pre);
		}
		return lstObjeto;
	}
}
